package com.cn.io.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;


/*
* transferTo() 方法是将数据从 FileChannel 传输到其他的 channel 中
*
* */
public class TransferTo {

    public static void main(String[] args) throws IOException {
        /*FileInputStream in = new FileInputStream("D:\\opt\\def.txt");
        FileOutputStream out = new FileOutputStream("D:\\opt\\abc.txt");
        byte[] bytes = new byte[1024];
        while (in.read(bytes) != -1) {
            out.write(bytes);
        }
        out.flush();
        in.close();
        out.close();*/
        FileChannel in = new FileInputStream("D:\\opt\\def.txt").getChannel();
        FileChannel out = new FileOutputStream("D:\\opt\\abc.txt").getChannel();
        in.transferTo(0, in.size(), out);
        in.close();
        out.close();
    }
}
